<template>
  <Form ref="formRef" :items="items" split-col="1" width="500px" style="margin-top: 20px;padding-right: 100px;"
        label-width="120" :show-reset="showReset"  @validateSuccess="validateSuccess" :rules="rules">

  </Form>
</template>

<script setup>

import Form from "@/components/plugs/form/Form.vue";
import {FormItemType} from "@/components/plugs/form/DialogFormInterface.js";
import {AXIOS_NAME} from "@/constant/constant.js"
import {inject, ref, toRaw} from "vue";
import {ElMessage} from "element-plus";

const $axios = inject(AXIOS_NAME);
const formRef = ref(null);
const showReset = false;

let items = [];
items.push({type: FormItemType.INPUT_HIDDEN,label: 'id',name: 'id'});
items.push({type: FormItemType.INPUT_TEXT, label: '接口地址', name: 'interfaceAddress'});
items.push({type: FormItemType.INPUT_TEXT,label: '请求方式',name: 'requestType'});
items.push({type: FormItemType.INPUT_TEXT,label: '接口描述',name: 'interfaceDesc'});
items.push({type: FormItemType.INPUT_TEXT, label: '配置文件', name: 'settingFilePath'});
items.push({type: FormItemType.INPUT_TEXT,label: '数据库名称',name: 'dbName'});
items.push({type: FormItemType.INPUT_TEXT,label: 'IP地址',name: 'dbIp'});
items.push({type: FormItemType.INPUT_TEXT,label: '用户名',name: 'dbUserName'});
items.push({type: FormItemType.INPUT_TEXT,label: '密码',name: 'dbPassword'});
const rules = {
  id: [
    { required: true, message: '请选择容器' }
  ],
};

const validateSuccess = (data) =>{
  $axios.post("/deploy/updateCustomParams",data).then(response =>{
    const data = response.data;
    if(data.code == 1){
      ElMessage.info(data.msg);
      return;
    }
    ElMessage.error(data.msg);
  });
}

const setData = (data) =>{
  formRef.value.setData(toRaw(data));
}

defineExpose({setData});

</script>

<style scoped>

</style>